package com.toe.user.webapi.service.impl;

import com.toe.commodity.service.CommodityClassesService;
import com.toe.commodity.service.CommodityGoodsService;
import com.toe.pojo.entity.user.UserHistory;
import com.toe.pojo.vo.commodity.CommodityClassVO;
import com.toe.pojo.vo.commodity.GoodsListDetailsVO;
import com.toe.pojo.vo.recommend.RecommendCommodityVO;
import com.toe.pojo.vo.user.UserHistoryVO;
import com.toe.user.webapi.mapper.UserHistoryMapper;
import com.toe.user.service.UserHistoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 陶涛
 * @since 2022-07-19
 */
@Service
@DubboService
public class UserHistoryServiceImpl extends ServiceImpl<UserHistoryMapper, UserHistory> implements UserHistoryService {

    @Autowired
    private UserHistoryMapper historyMapper;

    @DubboReference
    private CommodityGoodsService dubboCommodityGoodsService;

    @DubboReference
    private CommodityClassesService dubboCommodityClassesService;

    /**
     * 查询出没有被禁用的用户24小时内的历史浏览记录
     * @return
     */
    @Override
    public List<UserHistoryVO> listHistory() {
        return historyMapper.listHistory();
    }

    /**
     * 通过userId查询出用户24小时内浏览的商品的goods_id
     * @param userId
     * @return
     */
    @Override
    public List<Long> listGoodsByUserId(Long userId) {
        System.out.println("userId: "+userId);
        List<Long> list = historyMapper.listGoodsByUserId(userId);
        System.out.println("=========list.size = " + list.size());
        list.forEach(System.out::println);
        return list;
    }

    /**
     * 通过userId查询出用户24小时内浏览的商品的goods_id
     * @param userId
     * @return
     */
    @Override
    public List<Long> listGoodsById(Long userId) {
        System.out.println("userId: "+userId);
        List<Long> list = historyMapper.listGoodsById(userId);
        System.out.println("=========list.size = " + list.size());
        list.forEach(System.out::println);
        return list;
    }
    /**
     * 通过userId查询出用户24小时内浏览的课程的goods_id
     * @param userId
     * @return
     */
    @Override
    public List<Long> listClassByUserId(Long userId) {
        System.out.println("userId: "+userId);
        List<Long> list = historyMapper.listClassByUserId(userId);
        System.out.println("=========list.size = " + list.size());
        list.forEach(System.out::println);
        return list;
    }

    @Override
    public List<RecommendCommodityVO> getGoodsByGoodsIdList(List<Long> goodsIdList) {
        return dubboCommodityGoodsService.getCommodityGoodsByIds(goodsIdList);
    }

    @Override
    public List<CommodityClassVO> listClassByListClassID(List<Long> classIdList) {
        return dubboCommodityClassesService.getCommodityClassByIdList(classIdList);
    }

    //根据用户访问返回用户的浏览历史记录
    //需要返回用户id 商品id 商品类型(typeId:  0:商品 1:免费课 2:收费课 3:健身房)
    @Override
    public void insertHistory(Long userId, Long goodsId, int typeId) {
        historyMapper.insertHistory(userId,goodsId,typeId);
    }

    //清空历史记录
    @Override
    public void deletedAllHistoryByUserId(Long userId) {
        historyMapper.deletedAllHistoryByUserId(userId);
    }


}
